/**
 * @Description: 卡片信息的api封装
 * @author tao.xie
 * @date 2019-02-22
 */

import ajaxAsync from '../../src/utils/ajaxAsync'
import { CardInfoModel } from '../model/CardInfoModel'

/**
 * 获取卡列表
 */
async function getCardList () {
  let res = await ajaxAsync('/vcard/info/list', {},0, false)
  if (!res.LIST) {
    res.LIST = []
  }

  let cardlist = []

  res.LIST.map(item => {
    cardlist.push(new CardInfoModel(
      item.CARD_INSTANCE_ID,
      item.CARD_TYPE,
      item.CARD_NAME,
      item.STATE,
      item.CARD_OWNER,
      item.CARD_NO,
      item.AMOUNT,
      item.CARD_AMOUNT,
      item.FINAL_DISCOUNT
    ))
  })

  return cardlist
}

/**
 * 刷新二维码
 * @param cardno
 * @returns {Promise<*>}
 */
async function getQRCode (cardno) {
  return ajaxAsync('/vcard/QRCode', { CARD_NO: cardno })
}

export { getCardList, getQRCode }